// 监测对象下的多个属性, Map -> Set
let product = {price: 3, quantity: 2}, total = 0;
let depsMap = new Map();
let effect = () => {
	total = product.price * product.quantity
}

let track = (key) =>{
	let dep = depsMap.get(key);
	if(!dep){
		dep = new Set();
		depsMap.set(key, dep);
	}
	dep.add(effect)
}
let trigger = (key) =>{
	let dep = depsMap.get(key);
	if(!dep) return;
	dep.forEach(effect => effect());
}
track('price');
console.log(`total: ${total}`); // total: 0
effect();
console.log(`total: ${total}`); // total: 20
product.price = 20;
trigger('price');
console.log(`total: ${total}`); // total: 40
track('quantity');
product.quantity = 4;
trigger('quantity');
console.log(`total: ${total}`); // total: 40
